//
//  ExampleIndicatorsView.swift
//  SwiftUIFly
//
//  Created by shen on 2023/10/18.
//

import SwiftUI

struct ExampleIndicatorsView: View {
    @State private var progressAmount = 0.0
    @State private var progress = 0.5

    let timer = Timer.publish(every: 0.1, on: .main, in: .common).autoconnect()

    var body: some View {
        Group {
            ExampleSection(
                title: "ProgressView",
                description: "A view that shows the progress towards completion of a task.",
                content: {
                    Group {
                        ProgressView()
                        VStack {
                            ProgressView("Downloading…", value: progressAmount, total: 100)
                        }
                        .onReceive(timer) { _ in
                            if progressAmount < 100 {
                                progressAmount += 2
                            } else {
                                DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
                                    progressAmount = 0.0
                                }
                            }
                        }                       
                    }
                }
            )
        }
    }
}
